package GUILayer;
import ControlLayer.CtrOrderDetail;
import ModelLayer.OrderDetail;
import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

public class GUIOrderDetail extends javax.swing.JFrame {
    private CtrOrderDetail ctrOrderDetail;

    public GUIOrderDetail() {
        initComponents();
        ctrOrderDetail = CtrOrderDetail.getInstance();
        loadTableContent();
    }

    private void loadTableContent() {
        ((DefaultTableModel)tblOrderDetailList.getModel()).setRowCount(0);
        ArrayList<OrderDetail> orderDetailList = ctrOrderDetail.getOrderDetailList();
        for (OrderDetail orderDetail : orderDetailList) {
            ((DefaultTableModel)tblOrderDetailList.getModel()).addRow(
                new Object [] {
                    orderDetail.getIDOrderDetail(),
                    orderDetail.getIDOrder(),
                    orderDetail.getIDProduct(),
                    orderDetail.getIDProductAttribute(),
                    orderDetail.getProductName(),
                    orderDetail.getProductQuantity(),
                    orderDetail.getProductQuantityInStock(),
                    orderDetail.getProductQuantityRefunded(),
                    orderDetail.getProductQuantityReturn(),
                    orderDetail.getProductQuantityReinjected(),
                    orderDetail.getProductPrice(),
                    orderDetail.getProductQuantityDiscount(),
                    orderDetail.getProductEan13(),
                    orderDetail.getProductReference(),
                    orderDetail.getProductSupplierReference(),
                    orderDetail.getProductWeight(),
                    orderDetail.getTaxName(),
                    orderDetail.getTaxRate(),
                    orderDetail.getEcotax(),
                    orderDetail.getDownloadHash(),
                    orderDetail.getDownloadNB(),
                    orderDetail.getDownloadDeadline()
                }
            );
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrlOrderDetailList = new javax.swing.JScrollPane();
        tblOrderDetailList = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tblOrderDetailList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "id", "id_order", "id_product", "id_product_attribute", "product_name", "product_quantity", "product_quantity_in_stock", "product_quantity_refunded", "product_quantity_return", "product_quantity_reinjected", "product_price", "product_quantity_discount", "product_ean13", "product_reference", "product_supplier_reference", "product_weight", "tax_name", "tax_rate", "ecotax", "download_hash", "download_nb", "download_deadline"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Float.class, java.lang.Float.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Float.class, java.lang.String.class, java.lang.Float.class, java.lang.Float.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        scrlOrderDetailList.setViewportView(tblOrderDetailList);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrlOrderDetailList, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrlOrderDetailList, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIOrderDetail().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane scrlOrderDetailList;
    private javax.swing.JTable tblOrderDetailList;
    // End of variables declaration//GEN-END:variables
}
